<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>for的三种循环</title>
</head>
<body>
    <script>
        let lessons = [
            {lesson:"html",teacher:"Mr Lee"},
            {lesson:"css",teacher:"Mr Gao"},
            {lesson:"js",teacher:"Mr Liu"},
            {lesson:"php",teacher:"Mr Zhao"}
        ];

        // 普通for循环
        // for(let i = 0; i < lessons.length; i++){
        //     lessons[i].lesson = `xia_${lessons[i].lesson}`;
        // }

        // for...of...
        // for (const value of lessons) {
        //     value.lesson = `xia_${value.lesson}`;
        // }

        // for...in...
        for (const key in lessons) {
            lessons[key].lesson = `xia_${lessons[key].lesson}`;
        }
        console.log(lessons);



        let arr = [1,2,3,4,5];
        // value为基本数据类型时，值不变
        for (let value of arr) {
            value += 10;
        }
        console.log(arr);

        let arr1 = [{n:1},{n:2},{n:3}];
        // value为引用数据类型时，值会变
        for (let value of arr1) {
            value.n += 10;
        }
        console.log(arr1);
    </script>
</body>
</html>